#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime());
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_shutdown_clicked()
{
    QDateTime dateTime = ui->dateTimeEdit->dateTime();
    QDateTime currentTime = QDateTime::currentDateTime();
    uint i = dateTime.toTime_t()-currentTime.toTime_t();
    QString str = "shutdown -s -t " +QString::number(i);
    //ui->label_logo->setText(currentTime.toString());
    //system(str.toStdString().c_str());
    QProcess p(nullptr);
    p.start(str);
    p.waitForStarted();
    p.waitForFinished();
    qDebug()<<QString::fromLocal8Bit(p.readAllStandardError());
}

void MainWindow::on_pushButton_clicked()
{
    //system("shutdown -a");
    QProcess p(nullptr);
    p.start("shutdown -a");
    p.waitForStarted();
    p.waitForFinished();
    qDebug()<<QString::fromLocal8Bit(p.readAllStandardError());
}
